#include "UIStart.h"
#include "Common.h"
#include "GameScene.h"

UIStart::UIStart()
{

}

UIStart::~UIStart()
{

}

UIStart* UIStart::create()
{
	UIStart* p = new UIStart();
	if (p && p->init())
	{
		p->autorelease();
		return p;
	}

	CC_SAFE_DELETE(p);
	return p;
}

bool UIStart::init()
{
	bool bRet = false;
	do 
	{
		CC_BREAK_IF(!CCLayer::init());
		UILayer* pUILayer = UILayer::create();
		CC_BREAK_IF(!pUILayer);

		UILayout* pRoot = (UILayout*)GUIReader::shareReader()->widgetFromJsonFile("ui/start/start_1.json");
		pRoot->setSize(getContentSize());
		pUILayer->addWidget(pRoot);
		addChild(pUILayer);

		{
			UIButton* pBtn = dynamic_cast<UIButton*>(UIHelper::seekWidgetByTag(pRoot, EUIStartTag_play));
			CC_BREAK_IF(!pBtn);
			pBtn->addTouchEventListener(this, toucheventselector(UIStart::onPlay));
		}

		bRet = true;
	} while (0);

	return bRet;
}

void UIStart::onPlay(CCObject* pSender, TouchEventType eType)
{
	checkTouchEventTypeIsEnd(eType);
	CCDirector::sharedDirector()->replaceScene(CCTransitionProgressOutIn::create(1, GameScene::create()));
}

